package com.github.chirspan.xaas.auth.config;

import com.github.chirspan.xaas.auth.service.IntegrationUserDetailsService;
import com.github.chirspan.xaas.auth.integration.IntegrationAuthenticationFilter;
import com.github.chirspan.xaas.security.config.AbsAuthorizationServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;

/**
 * @author ChenPan
 * @date 2018/7/6 11:50
 * description:
 */
@Configuration
public class AuthorizationServerConfig extends AbsAuthorizationServerConfig {

    @Autowired
    private IntegrationAuthenticationFilter integrationAuthenticationFilter;

    @Autowired
    private IntegrationUserDetailsService integrationUserDetailsService;

    @Override
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        super.configure(endpoints);
        endpoints.userDetailsService(integrationUserDetailsService);
    }

    @Override
    public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception {
        super.configure(oauthServer);
        oauthServer.addTokenEndpointAuthenticationFilter(integrationAuthenticationFilter);
    }
}
